package data_structure;

import java.io.File;
import java.util.Vector;
import side_server.Server;

public class Files {
	private static Vector<String> 	files = new Vector<String>();
	private Vector<String>	retFiles = new Vector<String>();

	public Files()
	{
		super();
	}
	
	public static Vector<String> getFiles(String folder)
	{
		System.out.println("LOOKING FOR FILES IN FOLDER " + folder);
		File f = new File(folder);
		files = new Vector<String>();
		files.clear();
		if (f.isDirectory())
		{
			String[] ff = f.list();
			for(int i=0;i<ff.length;i++)
			{
				File tmp = new File(folder,ff[i]);
				boolean a = tmp.isFile();
				boolean b = tmp.getName().length()<21;
				boolean c = tmp.length()<51;
				
				if(a && b && c)
				{
					files.add(tmp.getName());
				}
			}
		}
		return files;
	}
	
	public Vector<String> getFileByWildcards(String wc)
	{
		wc=wc.toLowerCase();
		retFiles = new Vector<String>();
		for(int i=0;i<files.size();i++)
		{
			if(files.get(i).toLowerCase().matches(wc))
			{
				retFiles.add(files.get(i).toLowerCase());
			}
		}
		return retFiles;
	}
	
	public String getListFiles()
	{
		String ret = "";
		for(int i=0;i<files.size();i++)
		{
			ret+=files.get(i).toLowerCase()+Server.SEP;
		}
		return ret;
	}
}
